package is2.minga.packetProcessor;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;


import is2.misc.pipeAndFilter.OutPipeConnector;

public class InPacketProcessor implements Runnable
{
	private OutPipeConnector<String> pipe;
	private Integer port;
	
	public InPacketProcessor(OutPipeConnector<String> pipe, Integer inPort)
	{
		this.pipe = pipe;
		this.port = inPort;
				
	}
	
	
	public void run()
	{

		try {

			ServerSocket welcomeSocket = new ServerSocket(port);
	
			while (true)
			{
	
				Socket connectionSocket = welcomeSocket.accept(); 
				System.out.println("mensaje nuevo al packet processor");
				BufferedReader inFromClient = new BufferedReader(new
				InputStreamReader(connectionSocket.getInputStream())); 
				String msj = inFromClient.readLine();
				connectionSocket.close();
				pipe.Put(msj);
		
			}		

		} catch (Exception e) {
			System.err.println( "error en inpacketprocessor");
			System.err.println( e.toString());
		}	

	}

	
	
}
